<%--
  Created by IntelliJ IDEA.
  User: dong_
  Date: 2022/10/8
  Time: 10:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<form  method="post" enctype="multipart/form-data" id="loginForm">
    file: <input type="file" name="source"/> <br>
    <input type="text" name="username" >
</form>

<button type="button" id="btn">提交</button>

</body>
<script>
    $(function () {

        //1. 注册单击事件
        $("#btn").click(function () {

            // 获取表单数据，包含文件内容
            var form = new FormData(document.getElementById("loginForm"));

            // 发送ajxa请求
            $.ajax({
                url: "/upload/test3",
                type: "post",
                data: form,
                // 使用ajax请求去上传文件需要把如下两个属性设置为false，固定写法
                processData:false,
                contentType:false,
                success: function (result) {
                    console.log(result);
                },
                error:function (result) {
                    console.log(result);
                }
            });

        });

    });
</script>
</html>
